#pragma once

#include "IResourceObject.h"
#include "IRenderable.h"
#include "SceneNode.h"
#include "MacroDefs.h"
#include "SpriteAnimator.h"
#include <d3dx9.h>


enum DRAWING_MODE
{
	DM_NOALPHA = 1,
	DM_LIGHTMAP,
	DM_USEALPHA
};

enum SPRITE_FLIP
{
	SF_NONE = 0,
	SF_HORIZONTAL = 0x00000001,
	SF_VERTICAL = 0x00000010
};


class CResourceSprite: public CSceneNode, public IResourceObject, public IRenderable, public IAnimator
{
	protected:

	private:
		char*		_fileName;
		int			_width;
		int			_height;
		DWORD		_colorKey;

		LPD3DXSPRITE		_dxSprite;
		LPDIRECT3DTEXTURE9	_spriteTex;

		DRAWING_MODE	_drawMode;
		SPRITE_FLIP		_flip;
		bool			_colorOp;


	public:
		CResourceSprite();
		~CResourceSprite();


		bool CreateSprite(const char* fileName, int width, int height, DWORD colorKey);
		bool ReloadSprite(const char* fileName, int width, int height, DWORD colorKey);
		

		bool OnInitResource(ICompHandler* handler);
		bool OnFreeResource(ICompHandler* handler);

		void Render(LPDIRECT3DDEVICE9 rendererDevice, D3DXMATRIX*);

		void SetDrawMode(DRAWING_MODE t) { _drawMode = t; }
		void SetColorOp(bool s) { _colorOp = s; }

		IAnimator* GetAnimator() { return (IAnimator*)this; }

		//scene node virtuals
		bool IsRenderable() { return true; }
		void UpdateNode();
};
